<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>

<%
    String path = request.getContextPath();
			String basePath = request.getScheme() + "://"
					+ request.getServerName() + ":" + request.getServerPort()
					+ path + "/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>数独</title>
<script type="text/javascript"
	src="<%=basePath%>/js/jquery-1.7.1.min.js">
</script>
<script type="text/javascript">

	function validate(){
		$("#sudoValidate").attr("action","<%=basePath%>game/sudo/validateSudo.action");
		$("#sudoValidate").submit();
	}


	function changeSudoStatus(x,y){
		var value = $("#sudo\\.sudo\\["+x+"\\]\\["+y+"\\]").val();
		if(value>0 && value<10){
			$("#sudo\\.sudoStatus\\["+x+"\\]\\["+y+"\\]").val(2);
		} else{
			$("#sudo\\.sudoStatus\\["+x+"\\]\\["+y+"\\]").val(0);
		}
	}
	
	function changeSudoValue(x,y,div){
		var value = div.innerText;
		$("#sudo\\.sudo\\["+x+"\\]\\["+y+"\\]").val(value);
		changeSudoStatus(x,y);
	}
</script>
<style>
.sudo_empty {
	width: 15px;
	height: 15px;
	margin-bottom: 1px;
	margin-left: auto;
	margin-right: auto;
	padding: 1px;
	outline: 0;
	border: 1px solid #a0b3d6;
	overflow-x: hidden;
	overflow-y: hidden;
	text-align: center
}

.sudo_system {
	width: 15px;
	height: 15px;
	margin-bottom: 1px;
	margin-left: auto;
	margin-right: auto;
	padding: 1px;
	outline: 0;
	border: 1px solid #a0b3d6;
	overflow-x: hidden;
	overflow-y: hidden;
	text-align: center;
	background-color:#c2d5f8;
}
</style>
</head>
<body>
	<a href="<%=basePath%>">index|首页</a>
	<a href="<%=basePath%>game/sudo/generate.action?level=1">init|初始化</a>
	<a href="<%=basePath%>game/sudo/showResult.action">show|显示结果</a>
	<a href="<%=basePath%>game/sudo/promt.action">promt|提示</a>
	<hr>
	<h1>Game【Sudo】</h1>
	<hr>
	<form id="sudoValidate" action="" method="post">
		<table border="0">
			<thead>
				<tr>
					<th></th>
					<th>1</th>
					<th>2</th>
					<th>3</th>
					<th>4</th>
					<th>5</th>
					<th>6</th>
					<th>7</th>
					<th>8</th>
					<th>9</th>
				</tr>
			</thead>
			<s:iterator value="sudo.sudo" status="sudoRow">
				<tr>
					<td width="15px"><s:property value="#sudoRow.index+1" />|</td>
					<s:iterator value="sudo.sudo[#sudoRow.index]" status="sudoColum">
						<td width="15px" align="center"><s:if
								test="sudo.sudo[#sudoRow.index][#sudoColum.index]==0">
								<div class="sudo_empty" contenteditable="true"
									onkeyup="changeSudoValue(<s:property value="#sudoRow.index" />,<s:property value="#sudoColum.index" />,this)"></div>

								<input type="hidden"
									onchange="changeSudoStatus(<s:property value="#sudoRow.index" />,<s:property value="#sudoColum.index" />)"
									id="sudo.sudo[<s:property value="#sudoRow.index" />][<s:property value="#sudoColum.index" />]"
									name="sudo.sudo[<s:property value="#sudoRow.index" />][<s:property value="#sudoColum.index" />]"
									maxlength="1" style="width: 7px; height: 10px" />
								<input type="hidden"
									id="sudo.sudoStatus[<s:property value="#sudoRow.index" />][<s:property value="#sudoColum.index" />]"
									name="sudo.sudoStatus[<s:property value="#sudoRow.index" />][<s:property value="#sudoColum.index" />]"
									value="0" />
							</s:if> <s:elseif
								test="sudo.sudoStatus[#sudoRow.index][#sudoColum.index]==2">
								<div class="sudo_system"><font color="red"><s:property
											value="sudo.sudo[#sudoRow.index][#sudoColum.index]" /></font></div>
							</s:elseif> <s:else>
								<div class="sudo_system"><s:property
											value="sudo.sudo[#sudoRow.index][#sudoColum.index]" /></div>
										
							</s:else></td>
					</s:iterator>
				</tr>
			</s:iterator>
		</table>
		<button onclick="validate()">validate|验证</button>
	</form>
	<hr>
	<s:if test="!validateResult.equals(\"\")">
		<label>验证结果：<s:if test="validateResult">合法</s:if> <s:else>非法</s:else></label>
	</s:if>
</body>
</html>